package cn.wolfcode.trip.base.domain;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Setter;
import lombok.Getter;
import org.springframework.format.annotation.DateTimeFormat;

@Getter
@Setter
public class Question extends BaseDomain {
    public static final int TYPE_COMMON = 0; //默认类型
    public static final int TYPE_STRATEGY = 1; //攻略型问题
    public static final int TYPE_BORING = 2;  //无聊的问题

    private User user;

    private String title;

    private String content;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date askTime;

    private Integer type = TYPE_COMMON;

    public String getTypeName() {
        String temp = "默认类型";
        if (type == 1) {
            temp = "攻略型问题";

        } else if (type == 2) {
            temp = "无聊的问题";

        }
        return temp;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("title", title);
        map.put("content", content);
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        map.put("askTime", format.format(askTime));
        map.put("typeName", getTypeName());
        if (user != null) {
            map.put("nickName", user.getNickName());
            map.put("headImg", user.getHeadImgUrl());
        }

        return JSON.toJSONString(map);
    }

}